##########################################
# REPLICATION OF: 
#
# Traditional Institutions in Africa, Past and Present
#
# Political Science Research and Methods
#
# By Clara Neupert-Wentz and Carl Müller-Crepon, 2023
#
##########################################

** Introduction

This replication directory contains all analysis files to replicate results and figures in the article. For replication, please run the file "replicate_all.R". It will install all necessary packages, load all data, and source all files contained in the subdirectory "scripts". All tables and figures contained in the original article and appendix are saved to the respective folders in "results". Please see below for the mapping of figure and table filenames to numbers in the article and appendix. 


** Citation
Please cite: Neupert-Wentz, Clara and Carl Müller-Crepon (2023). Traditional Institutions in Africa, Past and Present. Political Science Research and Methods, X(XX), xxx-xxx. 


** Code files in "scripts" directory:
These files are, unless otherwise noted, sourced from the main file replication.R. 


analysis_constitut.R      Analysis of constitutionalization of trad. institutions, Figure A3
analysis_ethnicmatching.R Analysis of matching between TradGovGroups and Murdock data, Table A4
analysis_helperfunctions.R  Auxiliary functions, sourced from analysis_setup.R
analysis_indrule.R        Analysis of the effects of British vs. French rule on institutional persistence.
analysis_intercoder.R     Analysis of intercoder agreement in TradGovGroups data, Table A2
analysis_persistence.R    Analysis of overall institutional persistence
analysis_setup.R          Setup of analysis (paths, packages, etc)
libraries.R               Installation of all necessary libraries


** Data files in "data" directory:

main_data.rds             Main data file. Each row is one ethnic group by country, based on Murdock's data. 
intercoder_agree.rds      Data to compute intercoder agreement. Each row is one expert coding per group.
constitution_df.rds       Constitutionalization of trad. institutions data, based on Holzinger et al. (2019)



** Codebook of variables in main_data.rds

--- Identifiers
name                      Name of Murdock group
iso3c                     ISO code of country               
gid                       ID of Murdock group     


--- Baseline controls
pop.1880                  Population estimate, 1880 from HYDE        
coast.dist                Distance to the nearest coast               
river.dist                Distance to the closest river    

--- Variables from ethnographic atlas
v4.num                    Reliance on agriculture              
v5.num                    Reliance on pastoralism               
v28.num                   Intensity of agriculture               
v33.num                   Jurisdictional hierarchy     
poly.area                 Area of Murdock group's settlement area 
            
--- Geographic variables
max.cash.crop             Cash crop suitability (FAO GAEZ)            
medianaltitude            Altitude  (FAO GAEZ)              
medianslope               Terrain slope / ruggedness  (FAO GAEZ)              
evapotranspiration        Evapotranspiration  (FAO GAEZ)             
precipitation             Precipitation    (FAO GAEZ)            
ppetratio                 Precipitation / Evapotranspiration  (FAO GAEZ)          
temperaturemean           Average temperature  (FAO GAEZ)              
suit                      Agricultural suitability  (Ramankutty et al., 2002)         
malaria.tsuit.max         Malaria suitability               
tsetse.max                TseTse suitability      

--- Variables based on TradGovGroup data
group                     Concatenated group name(s)               
any_tpi                   Any traditional political institutions         
imp_day                   Importance of TPI in daily life              
imp_nat                   National importance of TPI               
tni_level_ord             TPI Level               
inst_mean                 Institution Index               
leader_mean               Leader Index              
leader_max                Max Leader               
ties_mean                 State-ties Index               
func_mean                 Functions Index               
tpi_pc1                   TPI Index              
tpi_centr_idx             Political Centralization               
tpi_funct_idx             Functional Differentiation               
tpi_pc1_nst               TPI Index, w/out state-ties               
tpi_funct_idx_nst         Functional Differentiation, w/out state-ties              

--- Colonization indicators
colonizer                 Colonizer (British, French, Other)               
colonizer.all             Colonizer, all               
french                    Dummy for French colonization               
british                   Dummy for British colonization              
v33.num_french            Interaction of French dummy and v33.num               
v33.num_british           Interaction of British dummy and v33.num              

*** Mapping of figure/table files to numbers

--- Figures

Main text:
- 2 scatter_indrule in analysis_indrule.R
- 3 v33_contemp_shortdv in analysis_persistence.R
- 4 v33_contemp_alldv in analysis_persistence.R
- 5 indrule_shortoutcomes in analysis_indrule.R
- 6 indrule_alloutcomes in analysis_indrule.R

Appendix: 
- A1 tradgovgrps_scatter in analysis_persistence.R ## CHECK
- A2 scatter_indrule_3out in analysis_indrule.R
- A3 const_colonizer in analysis_constitut.R

--- Tables

Appendix:
- A1 persistence.sumtab in analysis_indrule.R
- A2 intercoder_agree in analysis_intercoder.R
- A3 grps.pca.sum in analysis_persistence.R
- A4 matching_quality.tex in analysis_ethnicmatching.R
- A5 v33_contemp_main in analysis_persistence.R
- A6 indrule_main in analysis_indrule.R
- A7 indrule_splittpiidx in analysis_indrule.R
- A8 v33_contemp_nofe in analysis_persistence.R
- A9 indrule_nofe in analysis_indrule.R
- A10 indrule_fullint in analysis_indrule.R
- A11 indrule_nostateties in analysis_indrule.R
- A12 indrule_importance in analysis_indrule.R
- A13 indrule_matched in analysis_indrule.R
- A14 indrule_anytpi in analysis_indrule.R
- A15 indrule_select in analysis_indrule.R
- A16 indrule_selectreweight in analysis_indrule.R
- A17 indrule_rectozero in analysis_indrule.R